﻿#ifndef CTPDATASTORAGE_H
#define CTPDATASTORAGE_H

#include<QQueue>
#include <QList>
#include <QStringList>
#include <QSemaphore>
#include <QMutex>
#include <iostream>
#include <vector>
#include<QMap>
#include "../CommUtil/ComFun.h"
#include"../CommUtil/oracledao.h"

class CTPDataStorage
{
public:
    CTPDataStorage();
    ~CTPDataStorage();
    static void GetData(QStringList &strList, int nIndex);
    static void SetData(QStringList &strList, int nIndex);

    //更新5分钟K线数据
    static void Update5MinKLineData(QStringList &szHqList,int nIndex);
    //更新1分钟K线数据
    static void Update1MinKLineData(QString strContract,double lastPrice, long volume,int nIndex);
    static void Update1HourKLineData(QString strContract,double lastPrice, int nIndex);

    //保存1分钟K线数据
    static void Save1MinKLineData(OracleDAO &dao,QMap<QString,QString> &mapZhulian,QMap<QString,QString> &mapJinyue ,QMap<QString,ContractType> &MapContractType);
    //保存5分钟K线数据
    static void Save5MinKLineData(OracleDAO &dao,QMap<QString,QString> &mapZhulian,QMap<QString,QString> &mapJinyue ,QMap<QString,ContractType> &MapContractType);
    static void Save1HourKLineData(OracleDAO &dao,QMap<QString,QString> &mapZhulian,QMap<QString,QString> &mapJinyue ,QMap<QString,ContractType> &MapContractType);

private:
    static QMutex s_mutex[WORK_QUEUE];
    static QSemaphore s_sempData[WORK_QUEUE];

    //UPD 更改存储Ticks的结构为Queue start
    //static QList<QStringList> s_dataList[WORK_QUEUE];//存储TickData的List
    static QQueue<QStringList> s_dataQueue[WORK_QUEUE];//存储TickData的Queue
    //UPD 更改存储Ticks的结构为Queue end

    //储存1分钟K线的相关变量
    static QMap<QString,KLineType*> s_Map1MinKLine[WORK_QUEUE];
    static QMutex s_mutex1MinKLine[WORK_QUEUE];
    //储存5分钟K线的相关变量
    static QMap<QString,KLineType*> s_Map5MinKLine[WORK_QUEUE];
    static QMutex s_mutex5MinKLine[WORK_QUEUE];
    //储存1小时K线的相关变量
    static QMap<QString,KLineType*> s_Map1HourKLine[WORK_QUEUE];
    static QMutex s_mutex1HourKLine[WORK_QUEUE];
};

#endif // CTPDATASTORAGE_H
